﻿@{
    ViewBag.Title = "CouponSend";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}

<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                <a class="mini-button" id="batch" name="batch" iconCls="icon-edit" onclick="batch" plain="true">批量新增</a>
                 <span class="separator"></span>
                <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>
                <a class="mini-button" id="save" name="save" iconCls="icon-edit" onclick="modify" plain="true">修改</a>
                 <span class="separator"></span>
                <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="delInfo" plain="true">停用</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>       
</div>
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">发放时间：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">礼券类型：</td>
                <td width ="100px">    
                     @Html.Partial("~/Views/Modular/LookupCoupon.cshtml")
                </td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td width ="70px" align="right">礼券编码：</td>
                <td width ="310px">
                    <input name="CouponCode" class="mini-textbox" style="width:308px;"/>
                </td>
                <td width ="70px" align="right">礼券状态：</td>
                <td width ="150px">
                    <input id="StateFlag" name ="StateFlag" class="mini-combobox" style="width:100px;" 
                    showNullItem="false" required="true" allowInput="false" align="left" value="100" data ="dstateFlag"/>  
                </td>
                <td width ="70px" align="right">会员编号：</td>
                <td width ="100px">    
                    <input class="mini-textbox" width ="100px" id ="FSearchKey" name = "FSearchKey"/>                       
                </td>
            </tr>
        </table>
    </div>

        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetSendList"
                    allowCellSelect="true" showColumnsMenu="true" fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client" multiSelect="true">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FSendTime" name="FSendTime" width="100" headeralign="center" allowsort="true"  dateFormat="yyyy-MM-dd">发放时间</div>
                    <div field="FTypeName" name="FTypeName" width="100" headeralign="center" allowsort="true">礼券类型</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">礼券编码</div>
                    <div field="FAmount" name="FAmount" width="80" headeralign="center"align="right" allowsort="true" numberFormat="#,0.00">礼券面额</div>
                    <div field="FStartTime" name="FStartTime" width="100" headeralign="center"  align="right" allowsort="true"  dateFormat="yyyy-MM-dd">使用开始</div>
                    <div field="FEndTime" name="FEndTime" width="100" headeralign="center"  align="right" allowsort="true"  dateFormat="yyyy-MM-dd">截止使用</div>
                    <div field="FActStartTime" name="FActStartTime" width="100" headeralign="center"  align="right" allowsort="true"  dateFormat="yyyy-MM-dd">领券开始</div>
                    <div field="FActEndTime" name="FActEndTime" width="100" headeralign="center"  align="right" allowsort="true"  dateFormat="yyyy-MM-dd">领券结束</div>
                    <div field="FStatu" name="FStatus" width="60" headeralign="center" allowsort="true">礼券状态</div>
                    <div field="MemberNumber" name="MemberNumber" width="100" headeralign="center" allowsort="true">会员卡号</div>
                    <div field="MemberName" name="MemberName" width="80" headeralign="center" allowsort="true">会员名称</div>
                    <div field="FBillNo" name="FBillNo" width="150" headeralign="center" allowsort="true">单据编号</div>
                    <div field="FUseTime" name="FUseTime" width="100" headeralign="center" allowsort="true"  dateFormat="yyyy-MM-dd">消费时间</div>
                    <div field="FRemark" name="FRemark" width="260" headeralign="center" allowsort="true">备注</div>
                </div>
            </div>
        </div>

<script>
    var dstateFlag = [{ "id": "100", "text": "全部" },
                    { "id": "-1", "text": "停用" },
                    { "id": "0", "text": "发放" },
                    { "id": "1", "text": "已用" }];

    function FormShown() {
        mini.parse();
        var nowDate = new Date();
        mini.getbyName("FDate1").setValue(nowDate);
        mini.getbyName("FDate2").setValue(nowDate);
        LoadListData();
    }

    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
            var json = "[{";
            json = json + "'mSystemAppID':'" + sSystemAppID + "',";
            json = json + "'FDate1':'" + mini.getbyName("FDate1").getFormValue() + " 00:00:00',";
            json = json + "'FDate2':'" + mini.getbyName("FDate2").getFormValue() + " 23:59:59',";
            json = json + "'mCouponCode':'" + mini.getbyName("CouponCode").getValue() + "',";
            json = json + "'mStateFlag':'" + mini.getbyName("StateFlag").getValue() + "',";
            json = json + "'mMember':'" + mini.getbyName("FSearchKey").getValue() + "',";
            json = json + "'FCouponNumber':'" + mini.getbyName("FCouponNumber").getValue() + "'";
            json = json + "}]";
            var grid = mini.get("datagrid1");
            grid.load({ mjson: json });
    }

    function search() {
        LoadListData();
    }


    function newBill() {
        mini.open({
            url: "/Coupon/CouponGiveAway",
            title: "新增礼券发放", width: 630, height: 400,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row.FStatus < 1) {
            mini.open({
                url: "/Coupon/CouponGiveAway",
                title: "礼券发放", width: 630, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });
        }
        else {
            mini.alert("此券已消费不能更改");
        }
    }

    function batch() {
        mini.open({
            url: "/Coupon/CouponBatch",
            title: "批量新增礼券发放", width: 680, height: 350,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    function delInfo() {
        mini.confirm("确定要停用选中的记录吗？", "提示",
        function (action) {
            if (action == "ok") {
                removeInfo();
            }
        });
    }

    function removeInfo() {
        var grid = mini.get("datagrid1");
        var rows = grid.getSelecteds();
        if (rows) {
            var FSystemAppID = parent.window.getSystemAppID();
            var json = "[";
            for (var i = 0; i < rows.length; i++) {
                if (i > 0) json = json + ',';
                js = '{"FItemID":' + rows[i].FItemID + '}';
                json = json + js
            }
            json = json + "]";
            $.post("StopCouponSend", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == 1) {
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                    grid.reload();
                }
                else {
                    mini.alert("异常:" + ret.error);
                }
            });
        }
        else {
            mini.alert("请选中一条记录!");
        }
    }

</script>